<script src="<?php echo base_url()?>js/jquery.min.js" type="text/javascript"></script>
<script src="<?php echo base_url()?>js/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready( function() {
     $("#rec1").dialog({
		autoOpen: false,
		modal: true,
		width: '300'
	});
        $(function() {
            $('#loading').ajaxStart(function(){
                $(this).fadeIn();
            }).ajaxStop(function(){
                $(this).fadeOut();
            });

            var w = parseInt($('#week_count').val());
            for(var a=0;a<=w;a++){
                $('#click_cmb1'+a).click(function(){

                    if ($("#container3").is(":hidden")) {
                        $("#container3").slideDown("slow");
                        //$('#click').text('Tutup');
                    } else {
                        $("#container3").slideUp("slow");

                    }
                });
            }
            $('#menu_cm2 a').click(function() {
                var url = $(this).attr('href');
                $('#container3').load(url);
                return false;
            });




            //bulan kedua
            var ww = parseInt($('#week_count').val());
            for(var a=0;a<=ww;a++){
                $('#click_cmb2'+a).click(function(){

                    if ($("#container4").is(":hidden")) {
                        $("#container4").slideDown("slow");
                        //$('#click').text('Tutup');
                    } else {
                        $("#container4").slideUp("slow");

                    }
                });
            }
            $('#menu2 a').click(function() {
                var url = $(this).attr('href');
                $('#container4').load(url);
                return false;
            });


        });

    });
</script>

<?php $this->load->helper('HTML'); 
echo link_tag('css/style2.css');
echo link_tag('images/favicon.ico','shortcut icon','image/x-icon');
?>
<p>&nbsp;</p>

<h2 class="title">Calon Manager Khusus Dua Bulan</h2>
<form method="post">
    <table width="90%" border="0" cellpadding="1" cellspacing="1" id="data" align="center">
        <thead>
            <?php if(isset($error)) {?>
            <tr>
                <td colspan="5">
                        <?php echo $error?>
                </td>
            </tr>
                <?php }else { ?>
            <tr  align="center" class="table" >
        <input type="hidden" id="week_count" value="<?php echo count($weeks)?>">
        <th ><?php echo $bulan . " " . $tahun?></th>
            <?php for($i=0;$i<count($weeks);$i++):?>
        <th >Minggu Ke- <?php echo $weeks[$i]->intid_week;?></th>
            <?php endfor;?>
        <th >Total</th>

        </tr>
        </thead>
        <tbody>

            <!-- ============isi ============ -->
            <tr class='data'>
                <td>Penjualan Pribadi</td>
                    <?php
					//line ikhlas 
					//
                    $total=0;
                    $total_pv=0;
					//line ikhlas 
					$count_pribadi=0;
					$non_syarat_pribadi = 0;
					//end
					$count =0;
					
					for($i=0;$i<count($week_pribadi);$i++):?>
                <td align="center">
                            <?php
                            if(!empty($week_pribadi[$i][0]->total)) {
                                echo $week_pribadi[$i][0]->total;
                                $total = $total + $week_pribadi[$i][0]->total;
                                $count = $count +1;
								//untuk menghitung menjadi 4 bulan
								if($count <= 4){
									if($week_pribadi[$i][0]->total >= 300000){
										$count_pribadi = $count_pribadi + 1;
									}else{
										$non_syarat_pribadi = $non_syarat_pribadi +1;
									}
								}
                            }else {
                                echo "0";
                            }
                            ?>
                </td>
                    <?php endfor;?>
                <td align="center">
                        <?php //$total = 0;
                        echo number_format($total)?>
                </td>
            </tr>

            <tr class="data">
                <td>Rekrut Baru Pribadi</td>
                    <?php
                    $total_rekrut=0;
					//line ikhlas
					$count_jumlah = 0;
					$non_syarat_jumlah = 0;
					$count = 0;
					
                    for($i=0;$i<count($week_rekrut);$i++):?>
                <td align="center">
                            <?php
							
                            if(!empty($week_rekrut[$i][0]->total)) {
                                echo $week_rekrut[$i][0]->total;
                                $total_rekrut = $total_rekrut + $week_rekrut[$i][0]->total;
								//line ikhlas 
								//untuk syarat untuk mengajukan manajer
								$count = $count + 1;
								if($count <= 4){
									if($week_rekrut[$i][0]->total >= 1){
										$count_jumlah = $count_jumlah +1;
									}else{
										$non_syarat_jumlah = $non_syarat_jumlah + 1;
									}
								}
							}else {
                                echo "0";
                            }
                            ?>
                </td>
                    <?php endfor;?>
                <td align="center">
                        <?php echo $total_rekrut . " Orang"?>
                </td>
            </tr>
            <tr class="data">
                <td>Penjualan Rekrut</td>
                    <?php
					///coba di telaah kembali hitungan yang benernya	
					$total_jualrekrut=0;
							
					//line ikhlas
					$count_rekrut = 0;
					$non_syarat_rekrut = 0;
					$count = 0;
					
					for($i=0;$i<count($penjualanrekrut);$i++):?>
                <td align="center">
                            <?php
                            //print_r($penjualanrekrut[$i][0]->total);
                            if(!empty($penjualanrekrut[$i])) {
                                $pr = number_format($penjualanrekrut[$i][0]->total);
                                $week = $penjualanrekrut[$i][0]->intid_week;
                                $total_jualrekrut = $total_jualrekrut + $penjualanrekrut[$i][0]->total;
                                $count = $count + 1;
								if($count <= 4){
									if($penjualanrekrut[$i][0]->total >= 300000){
										$count_rekrut = $count_rekrut+1;
									}else{
										$non_syarat_rekrut = $non_syarat_rekrut +1;
									}
								}						
								?>
                    <div id="menu_cm2" style="height: 40px; width: 5px">
                                    <?php  echo anchor ('calon_manager/view_rekrut4/'.$strkode."/". $week."/".$bulan_a, ($pr), array('id' =>"click_cmb1".$i));?>
                    </div>

                                <?php
                            }else {
                                $pr = "0,00";
                                $week = 0;
                                echo $pr;
                            }
                            ?>

                </td>
                    <?php endfor;?>

                <td align="center">
                          <a href="<?php echo base_url().'calon_manager/extract_pengejaran_anak_langsung?strkode_dealer='.$strkode.'&bulan='.$bulan_a;?>"><?php echo number_format($total_jualrekrut)?></a>
                </td>
            </tr>
           
            <tr class="data">
                <td>&nbsp;</td>
                <td align="center" colspan="<?php echo count($weeks)?>">Penjualan anak/cucu diluar rekrut baru</td>
                <td align="center"><?php 
				 //echo number_format($penjualan_luar_rekrut_total);
				
					if(!empty($penjualan_luar_rekrut_total)){
						$totalpenjualan_luar_rekrut = $penjualan_luar_rekrut_total;
					}else{
							$totalpenjualan_luar_rekrut =0;
					}
					$tsatubulan = $totalpenjualan_luar_rekrut + ($total + $total_jualrekrut);
						if($tsatubulan >= 1600000) {
							$allowSave = '';
						}else {
							$allowSave = 'disabled';
						}
					$total_bener = $tsatubulan - $total - $total_jualrekrut;
					//$diluar = $total_bener;
				
				?>
				<a href="<?php echo base_url().'calon_manager/show_excelData?strkode='.$strkode.'&bulan='.$bulan_a;?>"><?php echo number_format($total_bener);?></a></td>
            </tr>
            <tr class="data">
                <td>&nbsp;</td>
                <td align="center" colspan="<?php echo count($weeks)?>">Total Pengejaran CM Bulan ke 1</td>
                <td align="center"><?php 
					$count_nominal = 0;
					$nominal = $total_bener + $total_jualrekrut + $total;
					if($nominal >= 7500000){
						$count_nominal = $count_nominal + 1;
					}
                        echo number_format($tsatubulan)?></td>
            </tr>

        </tbody>
            <?php } 
			
			?>
    </table>
</form>

<div id="container3" style="width:400px; height: 100px; display:none;">
		No Display Data
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<!-- Bulan Ke dua -->
<form method="post" id="frm" action="<?php echo $form_action?>">
    <table width="90%" border="0" cellpadding="1" cellspacing="1" id="data" align="center">
        <thead>
            <?php
            $tduabulan=0;
            $total_rekrutb2=0;
            if(isset($error2)) {?>
            <tr>
                <td colspan="5">
                        <?php echo $error2?>
                </td>
            </tr>
                <?php }else { ?>
            <tr  align="center" class="table" >
        <input type="hidden" id="week_count2" value="<?php echo count($weeks2)?>">
        <th ><?php echo $bulan1 . " " . $tahun?></th>
            <?php for($i=0;$i<count($weeks2);$i++):?>
        <th >Minggu Ke- <?php echo $weeks2[$i]->intid_week;?></th>
            <?php endfor;?>
        <th >Total</th>

        </tr>
        </thead>
        <tbody>

            <!-- ============isi ============ -->
            <tr class='data'>
                <td>Penjualan Pribadi</td>
                    <?php
                    $totalb2=0;
                    $total_pv1=0;
					//line ikhlas 
					$count =0;
					$count_pribadi=0;
					$non_syarat_pribadi = 0;
					
                    for($i=0;$i<count($week_pribadi2);$i++):?>
                <td align="center">
                            <?php
                            if(!empty($week_pribadi2[$i][0]->total)) {
                                echo $week_pribadi2[$i][0]->total;
                                $totalb2 = $totalb2 + $week_pribadi2[$i][0]->total;
                                $count = $count +1;
								if($count <= 4){
									if($week_pribadi2[$i][0]->total >= 300000){
										$count_pribadi = $count_pribadi + 1;
										}else{
											$non_syarat_pribadi = $non_syarat_pribadi +1;
										}
									}
                            }else {
                                echo "0";
                            }
                            ?>
                </td>
                    <?php endfor;?>
                <td align="center">
                        <?php //$total = 0;
                        echo number_format($totalb2)?>
                </td>
            </tr>

            <tr class="data">
                <td>Rekrut Baru Pribadi</td>
                    <?php
                    $total_rekrutb2=0;
                    for($i=0;$i<count($week_rekrut2);$i++):?>
                <td align="center">
                            <?php
                            if(!empty($week_rekrut2[$i][0]->total)) {
                                echo $week_rekrut2[$i][0]->total;
                                $total_rekrutb2 = $total_rekrutb2 + $week_rekrut2[$i][0]->total;
								$count = $count + 1;
								if($count <= 4){
									if($week_rekrut2[$i][0]->total >= 1){
										$count_jumlah = $count_jumlah +1;
									}else{
										$non_syarat_jumlah = $non_syarat_jumlah + 1;
									}
								}
                            }else {
                                echo "0";
                            }
                            ?>
                </td>
                    <?php endfor;?>
                <td align="center">
                        <?php echo $total_rekrutb2 . " Orang"?>
                </td>
            </tr>
            <tr class="data">
                <td>Penjualan Rekrut</td>
                    <?php
                    $total_jualrekrutb2=0;
					$count_rekrut = 0;
					$non_syarat_rekrut = 0;
					$count = 0;
					
					for($i=0;$i<count($penjualanrekrut2);$i++){
					echo ('<td align="center">');
                            //print_r($penjualanrekrut[$i][0]->total);
                    if(!empty($penjualanrekrut2[$i])) {
						$pr = number_format($penjualanrekrut2[$i][0]->total);
                        $week = $penjualanrekrut2[$i][0]->intid_week;
                        $total_jualrekrutb2 = $total_jualrekrutb2 + $penjualanrekrut2[$i][0]->total;
						$count = $count + 1;
						if($count <= 4){
							if($penjualanrekrut2[$i][0]->total >= 150000){
								$count_rekrut = $count_rekrut+1;
							}else{
								$non_syarat_rekrut = $non_syarat_rekrut +1;
							}
						}
						echo ('<div id="menu2" style="height: 40px; width: 5px">');
						echo anchor ('calon_manager/view_rekrut4/'.$strkode."/". $week."/".$bulan_b, ($pr), array('id' =>"click_cmb2".$i));
						echo ('</div>');
                    }else {
						$pr = "0,00";
                        $week = 0;
                        echo $pr;
                    }
					echo ('</td>');
					}
					?>

                <td align="center">
                          <a href="<?php echo base_url().'calon_manager/extract_pengejaran_anak_langsung?strkode_dealer='.$strkode.'&bulan='.$bulan_b;?>"><?php
                        echo number_format($total_jualrekrutb2)?></a>
                        <?php $tduabulan = ($totalb2 + $total_jualrekrutb2)+ $penjualan_luar_rekrut_total2; ?>
                </td>
          
            <tr class="data">
                <td>&nbsp;</td>
                <td align="center" colspan="<?php echo count($weeks2)?>">Penjualan anak/cucu diluar rekrut baru</td>
                <td align="center">
				<?php 
				// echo number_format($penjualan_luar_rekrut_total2);
				
						
				$total_bener2 = $tduabulan - $total_jualrekrutb2 - $totalb2;
				//echo $total_bener2;
				
				if(!empty($penjualan_luar_rekrut_total2)){
					$diluarb2 = $penjualan_luar_rekrut_total2;
				}else{
					$diluarb2 = 0;
				}
				 //echo number_format($diluarb2)
				 ?>
				 <a href="<?php echo base_url().'calon_manager/show_excelData?strkode='.$strkode.'&bulan='.$bulan_b;?>"><?php echo number_format($total_bener2);?></a></td>
            </tr>
            <tr class="data">
                <td>&nbsp;</td>
                <td align="center" colspan="<?php echo count($weeks2)?>">Total Pengejaran CM Bulan ke 2</td>
                <td align="center"><?php 
					$nominal = $total_bener2 + $total_jualrekrutb2 + $totalb2;
					if($nominal >= 7500000){
						$count_nominal = $count_nominal + 1;
					}
					echo number_format($tduabulan)?></td>
            </tr>

        </tbody>
            <?php } ?>
    </table>
</form>
<div id="container4" style="width:400px; height: 100px; display:none;">
		No Display Data
</div>
<form>
    <table width="90%" border="0" cellpadding="1" cellspacing="1" id="data" align="center">
        <tr class="data">
            <td align="center" colspan="4">Total Pengejaran CM Selama Dua Bulan</td>
            <td align="center"><?php
                $totcm2 = $tsatubulan + $tduabulan;
                echo number_format($totcm2);
                ?></td>
        </tr>
        <tr class="data">
            <td align="center" colspan="4">Rekrut Pribadi Baru</td>
            <td align="center"><?php
                $trekrutduabulan = $total_rekrutb2 + $total_rekrut;
                echo ($trekrutduabulan). " Orang";

                ?></td>
        </tr>
        <?php
		$nominal = $total_jualrekrut + $total + $total_bener + $total_jualrekrutb2 + $totalb2 + $total_bener2;
        
		$totpv = $total_pv + $total_pv1;
		
		if($count_rekrut == 8 and $count_jumlah == 8 and $count_pribadi == 8 and $count_nominal == 2 and $id_cabang == 1){
		   ?>
        <tr>
            <td colspan="5" align="left">
                <input type="hidden" name="strkode_dealer"  id="strkode_dealer" value="<?php echo $strkode?>">
                <input type="hidden" name="khusus"  id="khusus" value="<?php echo $khusus?>">
                <input type="hidden" name="total_omset"  id="total_omset" value="<?php echo $totcm2?>">
                <input type="hidden" name="total_pv"  id="total_pv" value="<?php echo $totpv?>">
                    
                <input type="submit" name="simpan" id="submit4" value="simpan"></td>
            <td colspan="2" align="center"></td>
        </tr>
            <?php }else { ?>
        <tr>
            <td colspan="5" align="center"><br>Tidak Memenuhi Syarat ! Belum bisa Melanjutkan ke Calon Manager Berikutnya</td>
        </tr>

            <?php
        }
        ?>
    </table>
</form>
<div id="message4"></div>
<script type="text/javascript">
    $(document).ready( function() {
        $('#submit4').click(function() {


            var form_data = {
                strkode_dealer : $('#strkode_dealer').val(),
                khusus : $('#khusus').val(),
                total_omset : $('#total_omset').val(),
                total_pv : $('#total_pv').val(),
                ajax : '1'
            };
            $.ajax({
                url: "<?php echo base_url(); ?>calon_manager/last_selection",
                type: 'POST',
                async : false,
                data: form_data,
                success: function(msg) {
                    $('#message4').html(msg);
                }
            });
            return false;
        });
    });
</script>